# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=miniserve
pkgver=0.28.0
pkgrel=0
pkgdesc="Quickly serve files via HTTP"
url="https://github.com/svenstaro/miniserve"
license="MIT"
# ring
arch="all !ppc64le !s390x !riscv64 !loongarch64"
makedepends="cargo cargo-auditable"
checkdepends="curl"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/svenstaro/miniserve/archive/v$pkgver/miniserve-$pkgver.tar.gz"

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release

	./target/release/miniserve --print-manpage > $pkgname.1

	./target/release/miniserve --print-completions bash > $pkgname.bash
	./target/release/miniserve --print-completions fish > $pkgname.fish
	./target/release/miniserve --print-completions zsh > $pkgname.zsh
}

check() {
	# seem to be broken in fakepty test but -q qrcode output works fine
	# bind_ipv4_ipv6::case2 fails on builders
	cargo test --frozen -- \
		--skip 'qrcode_shown_in_tty_when_enabled' \
		--skip 'qrcode_hidden_in_tty_when_disabled' \
		--skip 'bind_ipv4_ipv6::case_2'
}

package() {
	install -Dm755 target/release/miniserve "$pkgdir"/usr/bin/miniserve

	install -Dm644 $pkgname.1 "$pkgdir"/usr/share/man/man1/$pkgname.1

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
6ed06e2b221137b9e1b4ef6b047fc40ffc02869007fdd6cf30ed341ce404727d23a134f6b96b0330cafd462bcda82840b04bb5968a0f34fba3a504133b3a65ce  miniserve-0.28.0.tar.gz
"
